cmake_minimum_required(VERSION 3.5)

# include useful macros
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/util.cmake)

# read metadata from package.xml and setup project
xict_ui_metadata()

project(
    ${extracted_name}
    VERSION ${extracted_version}
    LANGUAGES C CXX
)

configure_file(
    ${PROJECT_SOURCE_DIR}/cmake/version.h.in
    ${PROJECT_SOURCE_DIR}/include/xict_ui_common/config/version.h
    @ONLY
)

# introduce default building settings
xict_ui_settings()

set(EXTRA_DEPS "")
set(EXTRA_INCLUDES "")

# find libraries
find_package(OpenCV REQUIRED)
include_directories(${OPENCV_INCLUDE_DIR})
find_package(fmt REQUIRED)
include_directories(/home/wq/lib/fmt/include/)

find_package(Threads REQUIRED)
find_package(Catch2 REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(eCAL REQUIRED)
find_package(Protobuf REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem)
find_package(yaml-cpp REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Quick)
set(QT_LIBRARIES Qt5::Quick)
find_package(xict_proto REQUIRED)
find_package(xict_common REQUIRED)

# include
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

include_directories(
    ${PROJECT_SOURCE_DIR}/include
)

# find all source files
file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*/*.cpp)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/xict_ui_core/*.h include/xict_ui_driver/basecansdk.h)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)

QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

xict_ui_library(
    NAME
    ${PROJECT_NAME}
    SRCS
    ${QT_SOURCES}
    ${QT_RESOURCES_CPP}
    ${QT_MOC_HPP}
    INCLUDES
    ${EXTRA_INCLUDES}
    DEPS
    ${QT_LIBRARIES}
    ${OpenCV_LIBRARIES}
    eCAL::core
    protobuf::libprotobuf
    ${CMAKE_DL_LIBS}
    ${Boost_LIBRARIES}
    ${Boost_FILESYSTEM_LIBRARY}
    ${YAML_CPP_LIBRARIES}
    fmt::fmt
    xict_proto::xict_proto
    xict_common::xict_common
    ${EXTRA_DEPS})

install(DIRECTORY ${PROJECT_SOURCE_DIR}/assets
    DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME})

xict_ui_apps()

include(CTest)
enable_testing()
xict_ui_tests("xict_ui")